{extend name="app/shop/view/base.html"/}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADDON_STOCK_CSS/stock.css"/>
{/block}
{block name="main"}
<div class="layui-form form">
	<div class="stock-view">
		<div class="store-view">
			<div class="layui-form-item">
				<div class="layui-inline">
					{if $stock_config.is_audit == 1}
					<div class="tips text-color">说明：待审核状态下只有经办人允许修改，只有变为已审核状态后才会使库存发生变化，已审核状态的单据不允许再修改。</div>
					{/if}
					<label class="layui-form-label"><span class="required">*</span>门店：</label>
					<div class="layui-input-block len-mid">
						<select name="store_id" lay-verify="required" lay-filter="store_list" class="len-mid">
							<option value="">请选择</option>
							{foreach $store_list as $store_k => $store_v}
							<option value="{$store_v.store_id}"  {if $store_k == 0}selected {php} $default_store_id = $store_v['store_id'];  {/php}{/if}>{$store_v.store_name}</option>
							{/foreach}
						</select>
					</div>
				</div>
			</div>
		</div>
		<table class="layui-table" lay-size="lg">
			<colgroup>
				<col width="450">
				<col width="120">
				<col width="120">
				<col>
				<col width="200">
				<col width="120">
				<col width="90">
			</colgroup>
			<thead>
				<tr>
					<th>商品名称/规格/编码</th>
					<th>当前库存</th>
					<th>销售库存</th>
					<th>单位</th>
					<th>实盘数量</th>
					<th>盈亏数量</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody class="stock-body">
				<tr class="stock-search-line">
					<td class="stock-search-block">
						<input type="text" class="layui-input stock-search" placeholder="请输入商品名称/规格/编码" style="border:none;padding-left:0;"/>
						<div class="stock-autocomplete-list">
							<ul></ul>
						</div>
					</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="8" class="total-data">合计: 共<span class="kinds-num">0</span>种商品, 盘盈：<span class="goods-up">0</span>种, 盘亏：<span class="goods-down">0</span>种, 持平：<span class="goods-same">0</span>种</td>
				</tr>
			</tfoot>
		</table>

		{notempty name="$inventory_info"}
		<input type="hidden" name="inventory_id" value="{$inventory_info['inventory_id']}">
		<input type="hidden" name="inventory_goods_list" value='{:json_encode($inventory_info["goods_list"])}'>
		{/notempty}

		<div class="form-row">
			<button class="layui-btn" lay-submit lay-filter="save">提交</button>
			<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
		</div>
	</div>

</div>

<script type="text/html"  id="stock_goods_info">
	<tr class="stock-tr" data-key = '{{ d.sku_id }}'>
		<td>
			<div class="ns-table-title">
				<div class="ns-title-pic" id="goods_img_{{d.sku_id}}">
					<img src="{{ns.img(d.sku_image, 'small')}}" layer-src/>
				</div>
				<div class="ns-title-content table-goods-info">
					<div>
						<a href="javascript:;" class="goods-name" title="{{d.sku_name}}" lay-event="preview">{{d.sku_name}}</a>
					</div>
				</div>
			</div>
			<input type="hidden" class="layui-input" name="goods_sku_id" value="{{ d.goods_sku_id || 0 }}"/>
			<input type="hidden" class="layui-input" name="stock" value="{{ d.real_stock || 0 }}"/>
		</td>

		<!-- 库存 -->
		<td>{{ d.real_stock || 0 }}</td>
		<td>{{ d.stock || 0 }}</td>
		<!-- 单位 -->
		<td>{{ d.unit }}</td>
		<!-- 数量 -->
		<td>
			<input type="number" class="layui-input stock-num" name="goods_num" value="{{ d.goods_num || '' }}" placeholder="0" onchange="dataChange(this)"/>
		</td>

		<!-- 成本总价 -->
		<td>
			<span class="compare-num">0</span>
		</td>
		<td>
			<a class="text-color action-btn" onclick="delTr(this)">删除</a>
		</td>
	</tr>
</script>
{/block}
{block name="script"}
<script>
	var stockData = JSON.parse($("input[name='inventory_goods_list']").val() || '{}');// 库存数据
	var defaultStoreId = {$default_store_id ?? 0};
	var stockConfig = {:json_encode($stock_config)};
	var stockAction = {
		id:'inventory_id',
		listRoute: 'check', // 库存操作标识，storage：入库，wastage：出库
		saveRoute: 'editcheck', // 保存地址
	};
</script>
<script src="ADDON_STOCK_JS/stock_action.js"></script>
{/block}